<?php
class SP_Validator_And
{
	protected $validator1;
	protected $validator2;
	
	
	private $input;
	private $result = array();
	
	public function __construct($attr=null)
	{
		if(is_array($attr))
		{
			foreach($attr as $key => $value)
			{
				$this->$key=$value;
			}
		}
	}
	
	public function setInput($value)
	{
		$this->input=$value;
	}
	
	public function validate1($value=null)
	{
		if(empty($value)) $value=$this->input;
		$this->validator1->setInput($value);
		if( $this->validator1->validate() )
		{
			return $this->result['validate1']=true;
		}
		else
		{
			return $this->result['validate1']=$this->validator1->getResultErrors();
		}
	}
	
	public function validate2($value=null)
	{
		if(empty($value)) $value=$this->input;
		$this->validator2->setInput($value);
		if( $this->validator2->validate() )
		{
			return $this->result['validate2']=true;
		}
		else
		{
			return $this->result['validate2']=$this->validator2->getResultErrors();
		}
	}
	
	public function validate()
	{
		$this->result=array();
		$this->validate1();
		$this->validate2();
		$out=true;
		foreach($this->result as $result)
		{
			if( $result!==true )
			{
				$out=false;
			}
		}
		return $out;
	}
	
	public function getResultErrors()
	{
		$out=array();
		foreach($this->result as $result)
		{
			if($result !== true)
			{
				$out=$result;
			}
		}
		return $out;
	}
		
	public function getResult()
	{
		return $this->result;
	}
}